﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Misuzilla.Crigate.Configuration;

namespace Misuzilla.Crigate.Handler
{
#if DEBUG
    [ActivateContext(ActivateContexts.SessionStarted)]
    [IsolatedAppDomain]
    public class TestHandler : MarshalByRefObject, IHandler, IMessageHandler
    {
        #region IHandler メンバ

        public void Initialize(Session session)
        {
            Trace.WriteLine(String.Format("{0}: HashCode={1}; AppDomainId={2}; AppDomain={3}", GetType().Name, GetHashCode(), AppDomain.CurrentDomain.Id, AppDomain.CurrentDomain));
        }

        public void Uninitialize()
        {
        }

        #endregion

        #region IDisposable メンバ

        public void Dispose()
        {
        }

        #endregion

        #region IMessageHandler<IrcMessage> メンバ

        public bool OnMessageReceived(Net.Irc.IrcMessage ircMessage)
        {
            System.Console.WriteLine("HandlerDomain: " + ircMessage.ToString());
            return true;
        }

        #endregion
    }
    
    [ActivateContext(ActivateContexts.SessionStarted)]
    [SharedAppDomain("TestHandler2Domain")]
    public class TestHandler2 : MarshalByRefObject, IHandler
    {
        #region IHandler メンバ

        public void Initialize(Session session)
        {
            Trace.WriteLine(String.Format("{0}: HashCode={1}; AppDomainId={2}; AppDomain={3}", GetType().Name, GetHashCode(), AppDomain.CurrentDomain.Id, AppDomain.CurrentDomain));
            var config = ConfigurationManager.GetConfigurationManager(session).GetConfig<TestConfiguration2>();
        }

        public void Uninitialize()
        {
        }

        #endregion

        #region IDisposable メンバ

        public void Dispose()
        {
        }

        #endregion
    }
    public class TestConfiguration2 : IConfiguration
    {
        public String Test { get; set; }
    }

    [ParentAppDomain]
    public class TestHandler3 : MarshalByRefObject, IHandler
    {
        #region IHandler メンバ

        public void Initialize(Session session)
        {
            Trace.WriteLine(String.Format("{0}: HashCode={1}; AppDomainId={2}; AppDomain={3}", GetType().Name, GetHashCode(), AppDomain.CurrentDomain.Id, AppDomain.CurrentDomain));
        }

        public void Uninitialize()
        {
        }

        #endregion

        #region IDisposable メンバ

        public void Dispose()
        {
        }

        #endregion
    }
#endif
}
